from datetime import datetime
import pandas as pd
from sqlalchemy import create_engine


class TgsVolumeMixin():
    """
    卡口流量预警模型
    """

    def __init__(self):
        """
        初始化，传入model参数
        :param model:
        """
        super().__init__()
        self.db = self.get_db('e', 'y', '10.2.1')

    # 暂定
    def get_db(self,user, password, ip, instance='orcl', port=1521):
        engine_str = 'oracle://%s:%s@%s:%s/%s' % (user, password, ip, port, instance)
        engine = create_engine(engine_str, encoding='utf-8')
        return engine

    def cal_tgsvolume(self):
        """
        算法执行
        :param data:
        :param dt:
        :return:
        """
        now = datetime.now()
        seg = pd.read_sql('select * from  t_sc t where rownum <10000', self.db)
        print(f'模型分析完成。 数据{len(seg)}条 {now}')
